package com.esun.cheetah.biz.odds;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.Handler;

import com.esun.cheetah.biz.personal.personalinfo.UserInfo;
import com.esun.cheetah.network.AbsInferiorityCommunicater;
import com.esun.cheetah.view.odds.info.EurOddsActInfoListInfo;

import com.esun.util.TimeUtil;
import com.esun.util.log.EDebug;

/**
 * 
 * @Package com.esun.cheetah.biz.personal.lotteryrecord.eurOddsActInfoListInfo
 * @ClassName: eurOddsActInfoListInfo
 * @Description: TODO(OddsInfoCommunicater)
 * @author handy <br/>
 * @date create at 2012-7-31 下午3:14:30
 * 
 */
public class EuroddsInfoCommunicater extends AbsInferiorityCommunicater {

	private ArrayList<EurOddsActInfoListInfo> returnList = new ArrayList<EurOddsActInfoListInfo>();

	ArrayList<EurOddsActInfoListInfo> modArrayList = new ArrayList<EurOddsActInfoListInfo>();
	private String status;
	private String msg;

	private String gamecount;
	private String dayofweek;
	private String daylist;

	public EuroddsInfoCommunicater(Handler handler) {
		super(handler);
	}

	@SuppressWarnings("static-access")
	@Override
	public HashMap<String, String> comHashMap() {
		HashMap<String, String> hmJson = new HashMap<String, String>();

		hmJson.put("id", "10062");
		hmJson.put("lotName", "jczq");
		hmJson.put("expect", TimeUtil.getInstance().sameDayFormat
				.format(Calendar.getInstance().getTime()));
		EDebug.o("TimeUtil.getInstance().getLatestRemoteTime().toString()-------------"
				+ TimeUtil.getInstance().sameDayFormat.format(Calendar
						.getInstance().getTime()));

		return hmJson;
	}

	@Override
	public void getJsonContent(String serverRes) throws JSONException {

		JSONObject json = new JSONObject(serverRes);
		status = json.getString("status");
		msg = json.getString("msg");
		UserInfo.getUserInfo().setMsg(msg);
		EDebug.o("msg---" + msg);
		EDebug.o("status---" + status);
		if ("true".equals(status)) {
			JSONObject jsondata = new JSONObject(json.getString("data"));
			String jsArray = jsondata.getString("league");
			EDebug.o("jsArray-----" + jsArray);
			JSONArray match = jsondata.getJSONArray("match");
			EDebug.o("match------" + match);
			String jsstaString = jsondata.getString("stat");
			EDebug.o("stat------" + jsstaString);
			JSONObject jsonObject = new JSONObject(jsstaString);
			gamecount = jsonObject.getString("gamecount");
			dayofweek = jsonObject.getString("dayofweek");
			daylist = jsonObject.getString("daylist");
			EDebug.o("daylist------" + daylist);
			EDebug.o("dayofweek------" + dayofweek);
			EDebug.o("gamecount------" + gamecount);

			for (int i = 0; i < 3; i++) {
				JSONArray localJs1 = match.optJSONArray(i);
				EDebug.o("localJs1-------" + localJs1);
				for (int j = 0; j < localJs1.length(); j++) {
					EurOddsActInfoListInfo eurOddsActInfoListInfo = new EurOddsActInfoListInfo();
					// }
					JSONObject localJs = localJs1.optJSONObject(j);
					// JSONArray localJs = localJs1.optJSONArray(j);
					EDebug.o("localJs-------" + localJs);
					if (localJs != null) {
						// status = localJs.getInt(Key.KEY_STATUS);
						String gamenum = localJs.getString("gamenum");
						EDebug.o("gamenum------" + gamenum);
						eurOddsActInfoListInfo.setMatchNum(gamenum);
						String resultspf = localJs.getString("resultspf");
						EDebug.o("resultspf------" + resultspf);
						eurOddsActInfoListInfo.setResultspf(resultspf);
						String homescore = localJs.getString("homescore");
						EDebug.o("homescore ------" + homescore);
						eurOddsActInfoListInfo.setHomescore(homescore);
						String awayscore = localJs.getString("awayscore");
						EDebug.o("awayscore ------" + awayscore);
						eurOddsActInfoListInfo.setAwayscore(awayscore);
						String matchnumdate = localJs.getString("matchnumdate");
						EDebug.o("matchnumdate---" + matchnumdate);
						eurOddsActInfoListInfo.setMatchNumDate(matchnumdate);
						String fixtureid = localJs.getString("fixtureid");
						EDebug.o("fixtureid---" + fixtureid);
						// eurOddsActInfoListInfo.setFixtureid(fixtureid);
						String seasonid = localJs.getString("seasonid");
						EDebug.o("seasonid---" + seasonid);
						// footballLotteryInfoListInfo.setSimpleleague(seasonid);
						String league = localJs.getString("league");
						EDebug.o("league---" + league);
						eurOddsActInfoListInfo.setDayOfWeek(league);
						String simpleleague = localJs.getString("simpleleague");
						EDebug.o("simpleleague---" + simpleleague);
						eurOddsActInfoListInfo.setSimpleLeague(simpleleague);
						String bgcolor = localJs.getString("bgcolor");
						EDebug.o("bgcolor---" + bgcolor);
						// footballLotteryInfoListInfo.setHomeid(bgcolor);
						String homesxname = localJs.getString("homesxname");
						EDebug.o("homesxname---" + homesxname);
						eurOddsActInfoListInfo.setHomeTeam(homesxname);
						String homeid = localJs.getString("homeid");
						EDebug.o("homeid---" + homeid);
						// footballLotteryInfoListInfo.setHomestanding(homeid);
						String homestanding = localJs.getString("homestanding");
						EDebug.o("homestanding---" + homestanding);
						eurOddsActInfoListInfo.setHomestanding(homestanding);
						String awayname = localJs.getString("awayname");
						EDebug.o("awayname---" + awayname);
						// footballLotteryInfoListInfo.setAwaysxname(awayname);
						String awaysxname = localJs.getString("awaysxname");
						EDebug.o("awaysxname---" + awaysxname);
						eurOddsActInfoListInfo.setVisitingTeam(awaysxname);
						String awaystanding = localJs.getString("awaystanding");
						EDebug.o("awaystanding---" + awaystanding);
						eurOddsActInfoListInfo.setAwaystanding(awaystanding);
						String matchtime = localJs.getString("matchtime");
						EDebug.o("matchtime---" + matchtime);
						// footballLotteryInfoListInfo.setMatchtime(matchtime);
						String matchdate = localJs.getString("matchdate");
						EDebug.o("matchdate---" + matchdate);
						// footballLotteryInfoListInfo.setMatchtime(matchdate);
						String endtime = localJs.getString("endtime");
						EDebug.o("endtime---" + endtime);
						// footballLotteryInfoListInfo.setEndtime(endtime);
						// String matchnumdate = localJs.getString("match?
						// footballLotteryInfoListInfo.setMatchtime(matchnumdate);
						String rangqiu = localJs.getString("rangqiu");
						EDebug.o("rangqiu---" + rangqiu);
						eurOddsActInfoListInfo.setRangQiu(rangqiu);
						// String status = localJs.getString("status");
						// EDebug.o("status---" + status);
						// footballLotteryInfoListInfo.setStatus(status);
						String score = localJs.getString("score");
						EDebug.o("score---" + score);
						eurOddsActInfoListInfo.setScore(score);
						// String win = localJs.getString("win");
						// EDebug.o("win---" + win);
						// footballLotteryInfoListInfo.setWin(win);
						// String draw = localJs.getString("draw");
						// EDebug.o("draw---" + draw);
						// footballLotteryInfoListInfo.setDraw(draw);
						// String lost = localJs.getString("lost");
						// EDebug.o("lost---" + lost);
						// footballLotteryInfoListInfo.setLost(lost);

						modArrayList.add(eurOddsActInfoListInfo);
						EDebug.o("modArrayList-------" + modArrayList);
						returnList.add(eurOddsActInfoListInfo);
					}
				}
				// EDebug.o("returnList-----before--" + returnList);
				// returnList.add(footballLotteryInfoListInfo);
				// EDebug.o("returnList-------" + returnList);
				EDebug.o("---------------------------1----------------------");

				EDebug.o("---------------------------2----------------------");
			}
			EDebug.o("---------------------------3----------------------");

		}

		// freezemoney = jsondata.getString("freezemoney");
		// EDebug.o("freezemoney----" + freezemoney);
		// setCk(jsondata.getString("ck"));
		// EDebug.o("ck----" + ck);
		// UserInfo.getUserInfo().setCk(ck);
		// UserInfo.getUserInfo().setUserName(username);
		// UserInfo.getUserInfo().setMoney(money);
		// }

	}

	public ArrayList<EurOddsActInfoListInfo> getFootballLotteryInfoList() {
		// listSportteryFootballAgainstInfos.get(location)
		return returnList;

	}

	// 保存竞彩足球开奖信息
	// public ArrayList<FootballLotteryInfoListInfo>
	// getFootballLotteryInfoList() {
	//
	// ArrayList<FootballLotteryInfoListInfo> returnList = new
	// ArrayList<FootballLotteryInfoListInfo>();
	//
	// int count = super.getListResult().size();
	// for (int i = 0; i < count; i++) {
	// FootballLotteryInfoListInfo lotteryInfo = new
	// FootballLotteryInfoListInfo();
	// lotteryInfo.setMatchNumDate(super.getListResult().get(i).get(Key.KEY_MATCHNUMDATE));
	// lotteryInfo.setDayOfWeek(super.getListResult().get(i).get(Key.KEY_DAYOFWEEK));
	// lotteryInfo.setHomeTeam(super.getListResult().get(i).get(Key.KEY_HOMESXNAME));
	// lotteryInfo.setRangQiu(super.getListResult().get(i).get(Key.KEY_RANGQIU));
	// lotteryInfo.setScore(super.getListResult().get(i).get(Key.KEY_SCORE));
	// lotteryInfo.setVisitingTeam(super.getListResult().get(i).get(Key.KEY_AWAYSXNAME));
	// lotteryInfo.setState(super.getListResult().get(i).get(Key.KEY_STATE));
	// lotteryInfo.setSimpleLeague(super.getListResult().get(i).get(Key.KEY_SIMPLELEAGUE));
	// lotteryInfo.setMatchNum(super.getListResult().get(i).get(Key.KEY_GAMENUM));
	// lotteryInfo.setHomeTeamImage(super.getListResult().get(i).get(Key.KEY_HOMESXNAMEID));
	// lotteryInfo.setVisitTeamImage(super.getListResult().get(i).get(Key.KEY_AWAYSXNAMEID));
	//
	// returnList.add(lotteryInfo);
	// }
	// return returnList;
	// }

	public String getStatus() {
		return this.status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getMsg() {
		return this.msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	// 返回比赛场次列表
	public String getCountList() {
		return gamecount;
	}

	public String getWeekList() {
		return dayofweek;
	}

	public String getDateList() {
		return daylist;
	}

	public int getState() {
		return 0;
	}

	public ArrayList<EurOddsActInfoListInfo> getReturnList() {
		return this.returnList;
	}

	public void setReturnList(ArrayList<EurOddsActInfoListInfo> returnList) {
		this.returnList = returnList;
	}

}
